<template>
  <div class="asset-manage-makerpn">
    <Form
      :label-width="120"
      ref="formValidate"
      :model="formData"
      :rules="formRule"
      inline
      class="asset-manage-makerpn-info"
    >
      <div class="ivu-table ivu-table-default  ivu-table-noborder">
        <div class="ivu-table-body table-border-none">
          <table cellspacing="0" cellpadding="0" border="0" style="width: 100%;">
            <tbody class="ivu-table-tbody">
              <tr class="ivu-table-row">
                <td colspan="2">
                  <div class="ivu-table-cell">
                    <h3 class="title"><span class="title-icon"></span> <span>编码信息</span></h3>
                  </div>
                </td>
              </tr>
              <tr class="ivu-table-row">
                <td colspan="2">
                  <div class="ivu-table-cell">
                    <FormItem prop="name" label="标准名称：">
                      <Input
                        v-model="formData.name"
                        :maxlength="32"
                        :disabled="codeDisabled"
                        class="input-width"
                        placeholder="填写不超过32个字符，非特殊编码"
                      />
                    </FormItem>
                  </div>
                </td>
              </tr>
              <tr class="ivu-table-row">
                <td class="none-border">
                  <div class="ivu-table-cell">
                    <FormItem prop="machineCategoryId" label="一级分类：">
                      <Select
                        :disabled="codeDisabled"
                        @on-change="handleMachineCategory"
                        v-model="formData.machineCategoryId"
                        :label-in-value="true"
                        transfer
                        placeholder="请选择"
                        class="input-width"
                      >
                        <Option
                          v-for="item in machineCategoryIdData"
                          :value="item.machineCategoryId"
                          :label="item.name"
                          :key="item.machineCategoryId"
                          >{{ item.name }}</Option
                        >
                      </Select>
                      <!-- <Input class="input-width" placeholder="填写不超过32个字符，非特殊编码" /> -->
                    </FormItem>
                  </div>
                </td>
                <td class="none-border">
                  <div class="ivu-table-cell">
                    <FormItem prop="subMachineCategoryId" label="二级分类：">
                      <Select
                        :disabled="codeDisabled"
                        @on-change="handleSubMachineCategory"
                        :label-in-value="true"
                        v-model="formData.subMachineCategoryId"
                        transfer
                        placeholder="请选择"
                        class="input-width"
                      >
                        <Option
                          v-for="item in subMachineCategoryIdData"
                          :value="item.machineCategoryId"
                          :label="item.name"
                          :key="item.value"
                          >{{ item.name }}</Option
                        >
                      </Select>
                    </FormItem>
                  </div>
                </td>
              </tr>
              <tr class="ivu-table-row">
                <td class="none-border">
                  <div class="ivu-table-cell">
                    <FormItem prop="nameAbbreviation" label="名字缩写：">
                      <Input
                        :disabled="codeDisabled"
                        v-filterinput="{ reg: regExp.noLetter, type: 'toUpperCase' }"
                        v-model="formData.nameAbbreviation"
                        :maxlength="2"
                        class="input-width"
                        placeholder="仅允许填写两个英文大写字符"
                      />
                    </FormItem>
                  </div>
                </td>
                <td class="none-border">
                  <div class="ivu-table-cell">
                    <FormItem prop="machineVersion" label="机台版本号：">
                      <Select
                        :disabled="codeDisabled"
                        v-model="formData.machineVersion"
                        transfer
                        placeholder="请选择"
                        class="input-width"
                      >
                        <Option v-for="item in versionsData" :value="item.value" :key="item.value">{{
                          item.label
                        }}</Option>
                      </Select>
                    </FormItem>
                  </div>
                </td>
              </tr>
              <tr class="ivu-table-row">
                <td class="none-border">
                  <div class="ivu-table-cell">
                    <FormItem prop="abbreName" label="供应商名称/VN：">
                      <Input
                        v-if="codeDisabled"
                        :disabled="codeDisabled"
                        :maxlength="2"
                        :value="formData.supplierName"
                        class="input-width"
                        placeholder="仅允许填写两个英文大写字符"
                      />
                      <sass-select
                        v-if="!codeDisabled"
                        v-model="formData.abbreName"
                        :disabled="codeDisabled"
                        @on-change="handleCodeChange"
                        :loading="loading"
                        remote
                        label-in-value
                        :remote-method="handleRemoteMethod"
                        transfer
                        filterable
                        placeholder="请输入搜索"
                        class="input-width"
                      >
                        <Option
                          v-for="(item, index) in pnCodeData"
                          :value="item.suppNameShorten"
                          :label="item.suppName"
                          :key="index"
                          >{{ item.suppName }}</Option
                        >
                      </sass-select>
                    </FormItem>
                  </div>
                </td>
                <td class="none-border">
                  <div class="ivu-table-cell">
                    <FormItem prop="yearCorp" label="上市年份：">
                      <DatePicker
                        :disabled="codeDisabled"
                        v-model="formData.yearCorp"
                        :options="options"
                        transfer
                        :editable="false"
                        :clearable="false"
                        type="year"
                        placeholder="请选择"
                        class="input-width"
                      ></DatePicker>
                      <!-- <Input class="input-width" placeholder="填写不超过32个字符，非特殊编码" /> -->
                    </FormItem>
                  </div>
                </td>
              </tr>
              <tr class="ivu-table-row">
                <td class="none-border">
                  <div class="ivu-table-cell">
                    <FormItem prop="salesAmount" label="销售单位：">
                      <Select
                        :disabled="codeDisabled"
                        v-model="formData.salesAmount"
                        transfer
                        placeholder="请选择"
                        class="input-width"
                      >
                        <Option v-for="item in salesAmountData" :value="item.value" :key="item.value">{{
                          item.label
                        }}</Option>
                      </Select>
                    </FormItem>
                  </div>
                </td>
                <td class="none-border">
                  <div class="ivu-table-cell">
                    <FormItem prop="slotQuantity" label="游戏位数量：">
                      <Select
                        :disabled="codeDisabled"
                        v-model="formData.slotQuantity"
                        transfer
                        placeholder="请选择"
                        class="input-width"
                      >
                        <Option v-for="item in slotQuantityData" :value="item.value" :key="item.value">{{
                          item.label
                        }}</Option>
                      </Select>
                    </FormItem>
                  </div>
                </td>
              </tr>
              <tr class="ivu-table-row">
                <td></td>
                <td class="none-border">
                  <div class="ivu-table-cell">
                    <!-- <FormItem > -->
                    <!-- <Row type="flex" justify="end"> -->
                    <FormItem>
                      <Row type="flex" justify="end" class="input-width">
                        <Button :disabled="codeDisabled" @click="handleGenerateCode" type="primary">生成编码</Button>
                      </Row>
                    </FormItem>
                    <!-- </Row> -->

                    <!-- </FormItem> -->
                  </div>
                </td>
              </tr>

              <tr class="ivu-table-row">
                <td></td>
                <td></td>
              </tr>
              <tr class="ivu-table-row">
                <td colspan="2">
                  <div class="ivu-table-cell">
                    <h3 class="title"><span class="title-icon"></span> <span>PN生成</span></h3>
                  </div>
                </td>
              </tr>
              <tr class="ivu-table-row">
                <td colspan="2">
                  <div class="ivu-table-cell">
                    <FormItem prop="pnCode" label="产品编码：">
                      <Input
                        v-model="formData.pnCode"
                        :readonly="!formData.pnCode"
                        :disabled="!!formData.pnCode"
                        class="input-width"
                        placeholder="自动根据编码信息生成"
                      />
                    </FormItem>
                  </div>
                </td>
              </tr>

              <tr class="ivu-table-row">
                <td></td>
                <td></td>
              </tr>
              <tr class="ivu-table-row">
                <td colspan="2">
                  <div class="ivu-table-cell">
                    <h3 class="title"><span class="title-icon"></span> <span>基础信息</span></h3>
                  </div>
                </td>
              </tr>
              <tr class="ivu-table-row">
                <td colspan="2">
                  <div class="ivu-table-cell">
                    <FormItem label="上传图片：">
                      <div style="display:flex;">
                        <div
                          style="display:flex;flex-direction: column;"
                          v-for="(item, index) in uploadList"
                          :key="index"
                        >
                          <!-- v-if="item.status === 'finished'" -->
                          <template v-if="item.status === 'finished'">
                            <div class="upload-list">
                              <img :src="item.url" />
                              <p class="upload-list-p" v-if="imgIndex === index">商品主图</p>
                              <div v-if="!baseDisabled" class="upload-list-cover">
                                <!-- <Icon size="20" type="ios-eye-outline"></Icon> -->
                                <Icon size="30" @click="handleRemove(index)" type="ios-trash-outline">删除</Icon>
                              </div>
                            </div>

                            <Button
                              v-if="imgIndex !== index && !baseDisabled"
                              @click="handleImg(index)"
                              class="upload-list-button"
                              size="small"
                              type="primary"
                              >设置为主图</Button
                            >
                          </template>
                        </div>
                        <Upload
                          v-show="!baseDisabled"
                          ref="upload"
                          :show-upload-list="false"
                          :on-success="handleSuccess"
                          :default-file-list="defaultList"
                          :format="['jpg', 'jpeg', 'png']"
                          :max-size="5120"
                          :on-format-error="handleFormatError"
                          :on-exceeded-size="handleMaxSize"
                          :before-upload="handleBeforeUpload"
                          multiple
                          type="drag"
                          :action="$config.uploadImg"
                          style="display: inline-block;width:96px;"
                        >
                          <div style="width: 96px;height:96px;line-height: 96px;">
                            <Icon type="ios-add" size="20"></Icon>
                          </div>
                        </Upload>
                      </div>
                    </FormItem>
                  </div>
                </td>
              </tr>

              <tr class="ivu-table-row">
                <td></td>
                <td></td>
              </tr>
              <tr class="ivu-table-row">
                <td colspan="2">
                  <div class="ivu-table-cell">
                    <h3 class="title"><span class="title-icon"></span> <span>物理信息</span></h3>
                  </div>
                </td>
              </tr>
              <tr class="ivu-table-row">
                <td colspan="2">
                  <div class="ivu-table-cell">
                    <FormItem label="相关参数：">
                      <div class="ivu-table-wrapper">
                        <div class="ivu-table ivu-table-default  ivu-table-border">
                          <div class="ivu-table-header">
                            <table cellspacing="0" cellpadding="0" border="0" style="width: 100%;">
                              <colgroup>
                                <col width="40%" />
                                <col width="60%" />
                              </colgroup>
                              <thead>
                                <tr>
                                  <th>
                                    <div class="ivu-table-cell">
                                      <span class>参数类型</span>
                                    </div>
                                  </th>
                                  <th>
                                    <div class="ivu-table-cell">
                                      <span class>录入参数</span>
                                    </div>
                                  </th>
                                </tr>
                              </thead>
                            </table>
                          </div>
                          <div class="ivu-table-body">
                            <table cellspacing="0" cellpadding="0" border="0" style="width: 100%;">
                              <colgroup>
                                <col width="40%" />
                                <col width="60%" />
                              </colgroup>
                              <tbody class="ivu-table-tbody">
                                <!---->
                                <tr v-for="(item, index) in physics" :key="index" class="ivu-table-row">
                                  <td>
                                    <div class="ivu-table-cell">
                                      {{ item.label }}
                                    </div>
                                  </td>
                                  <td style="height:80px">
                                    <div style="overflow: inherit;" class="ivu-table-cell">
                                      <!-- {{ item.key }} -->
                                      <FormItem :prop="item.key">
                                        <Input
                                          v-model="formData[item.key]"
                                          v-if="item.key === 'approvalNo'"
                                          :disabled="baseDisabled"
                                          :maxlength="100"
                                          class="input-width"
                                          :placeholder="item.placeholder"
                                        />
                                        <Input
                                          v-model="formData[item.key]"
                                          v-else
                                          v-filterinput="{ reg: item.key === 'weight' ? regExp.nand : regExp.nan }"
                                          :disabled="baseDisabled"
                                          :maxlength="item.key === 'weight' ? 9 : 6"
                                          class="input-width"
                                          :placeholder="item.placeholder"
                                        />
                                      </FormItem>

                                    </div>
                                  </td>
                                </tr>
                              </tbody>
                            </table>
                          </div>
                        </div>
                      </div>
                    </FormItem>
                  </div>
                </td>
              </tr>
              <tr class="ivu-table-row">
                <td  colspan="2">
                  <div class="ivu-table-cell">
                    <FormItem>
                      <Button
                        :disabled="baseDisabled"
                        style="width: 100px; margin-right: 20px;"
                        @click="handleSubmit"
                        type="primary"
                        >确认</Button
                      >
                      <Button style="width: 100px;" @click="handleCancle">取消</Button>
                    </FormItem>
                  </div>
                </td>
              </tr>
            </tbody>
          </table>
        </div>
      </div>
    </Form>
    <!-- pn生成器 -->
  </div>
</template>
<script>
import { categoryList, machineSave, supplierList, machineQuery } from '@/api/asset/repair/asset-manage'
import regExp from '@/libs/regExp'
import dayjs from 'dayjs'
import errorCaptured from '@/libs/errorCaptured'
import sassSelect from '@/components/sass-select'
import { cloneObj } from '@/libs/cloneObj'
import { routeEqual } from '@/libs/util'
// import { resolve } from 'dns'
export default {
  name: 'makerpn-component',
  components: { sassSelect },
  data () {
    const validate = (rule, value, callback) => {
      // // console.log(this)
      // debugger
      if (value === '') return callback()
      value = Number(value)
      if (Number.isNaN(value)) return callback(new Error('请输入数字'))
      if (rule.field === 'weight') {
        if (!regExp.numLen6D2.test(value)) return callback(new Error('请输入六位数的整数可带两位小数'))
      } else {
        if (!regExp.numLen6.test(value)) return callback(new Error('请输入六位数的整数'))
      }
      // callback(new Error('情书'))
      callback()
    }
    return {
      uploadList: [],
      defaultList: [],
      regExp: regExp,
      formData: {
        name: '', // 名称
        machineCategoryId: '', // 一级分类
        subMachineCategoryId: '', // 二级分类
        nameAbbreviation: '', // 名字缩写
        machineSupplierId: '', // 供应商id
        abbreName: '', // 供应商缩写
        yearCorp: '', // 时间
        salesAmount: '', // 销售数量
        machineVersion: '', // 版本号
        // seat: '', // 游戏位
        slotQuantity: '', // 投币口数
        pnCode: '', // PN码
        power: '', // 功率
        weight: '', // 净重
        length: '', // 长
        width: '', // 宽
        height: '', // 高
        approvalNo: '' // 文化审批号
      },
      copyData: {}, // 存储已经生成PN的数据
      loading: false,
      imgIndex: 0, // 图片主图
      salesAmountData: [], // 销售单位
      machineCategoryIdData: [], // 一级分类
      subMachineCategoryIdData: [], // 二级分类
      versionsData: [], // 版本号
      slotQuantityData: [], // 游戏位
      merchantId: this.$store.state.user.merchantId.toLocaleLowerCase(),
      formRule: {
        name: [{ required: true, message: '请输入名字', trigger: 'blur' }],
        machineCategoryId: [{ required: true, message: '请选择一级分类' }],
        subMachineCategoryId: [{ required: true, message: '请选择二级分类' }],
        nameAbbreviation: [
          { required: true, message: '请输入名字缩写', trigger: 'blur' },
          { type: 'string', min: 2, message: '只能输入两个字符', trigger: 'blur' },
          { type: 'string', max: 2, message: '只能输入两个字符', trigger: 'blur' }
        ],
        machineVersion: [{ required: true, message: '请选择机台版本号' }],
        abbreName: [
          { required: true, message: '请选择供应商' }
          // { type: 'string', min: 2, message: '只能输入两个字符' },
          // { type: 'string', max: 2, message: '只能输入两个字符', trigger: 'blur' }
        ],
        yearCorp: [{ required: true, message: '请选择时间' }],
        salesAmount: [{ required: true, message: '请选择销售单位' }],
        slotQuantity: [{ required: true, message: '请选择游戏位数量' }],
        pnCode: [{ required: true, message: '请生成PN编码', trigger: 'change' }],
        power: [{ validator: validate, trigger: 'blur' }],
        weight: [{ validator: validate, trigger: 'blur' }],
        length: [{ validator: validate, trigger: 'blur' }],
        width: [{ validator: validate, trigger: 'blur' }],
        height: [{ validator: validate, trigger: 'blur' }]
      },
      machineList: [], // 机台分类
      pnCodeData: [],
      options: {
        disabledDate: (date) => {
          return dayjs(date) <= dayjs('2004') || dayjs(date) > dayjs('2050')
        }
      },
      // 物理信息
      physics: [
        { key: 'power', label: '功率', placeholder: '输入6位数字，单位瓦' },
        { key: 'weight', label: '净重', placeholder: '输入小数点前6位及后2位，单位公斤' },
        { key: 'length', label: '长', placeholder: '输入6位数字，单位毫米' },
        { key: 'width', label: '宽', placeholder: '输入6位数字，单位毫米' },
        { key: 'height', label: '高', placeholder: '输入6位数字，单位毫米' },
        { key: 'approvalNo', label: '文化审批号', placeholder: '请输入' }
      ],
      PN: {
        C: '', // 一级分类
        Y1: '', // 二级分类
        Y2Y3: '', // 机台名称缩写
        Y4Y5: '', // 机台版本号
        AB: '', // 供应商缩写
        M: '', // 销售数量
        N: '', // 投币口数量
        XX: '' // 年份
      }
    }
  },
  computed: {
    codeDisabled () {
      return this.$route.name === 'asset_manage_product_control_detail' || this.$route.name === 'asset_manage_product_control_edit'
    },
    baseDisabled () {
      return this.$route.name === 'asset_manage_product_control_detail'
    }
  },
  created () {
    // CY1Y2Y3Y4Y5 – AB –XX– MN
    this.versionsData = Array.from(new Array(50).keys(), x => {
      return { value: x + 1, label: x + 1 }
    })
    this.salesAmountData = Array.from(new Array(9).keys(), x => {
      return { value: x + 1, label: x + 1 }
    })
    this.slotQuantityData = Array.from(new Array(99).keys(), x => {
      return { value: x + 1, label: x + 1 }
    })
    // console.log(this.$route)
    this.categoryList()
  },
  mounted () {
    this.uploadList = this.$refs.upload.fileList
  },
  methods: {
    // 远程搜索
    async handleRemoteMethod (query) {
      if (this.timer) clearTimeout(this.timer)
      this.timer = setTimeout(async () => {
        this.loading = true
        const res = await supplierList({ keyword: query, dispFlag: 2, merchantId: this.merchantId, displayOrder: 1, supplierTypeCode: 2 })
        this.loading = false
        if (res.data.status !== 200) return this.$Message.error(res.data.error)
        this.pnCodeData = res.data.data || []
      }, 500)
      // console.log(query)
    },
    // 供应商选择
    handleCodeChange (val) {
      this.formData.machineSupplierId = this.pnCodeData
        .filter(item => item.suppNameShorten === val.value)
        .map(item => item.id)
        .join()
    },
    // 上传文件
    handleSuccess (res, file) {
      file.url = file.response.full_img_url
      // this.uploadList.push(res.full_img_url)
      // console.log(res)
      // console.log(file)
    },
    // 上传错误
    handleFormatError () {},
    handleMaxSize (file) {
      this.$Message.error('图片最大5MB')
    },
    handleBeforeUpload (file) {
      let check = this.uploadList.length < 5
      if (!check) {
        this.$Message.error('最多上传5张')
      }
      if (file.size / 1024 < 50) {
        this.$Message.error('图片最小50KB')
        check = false
      }
      console.log(file.size)
      return check
    },
    // 删除图片
    handleRemove (index) {
      // let fileList = this.$refs.upload.fileList
      this.$refs.upload.fileList.splice(index, 1)
      if (this.imgIndex === index) {
        this.imgIndex = 0
      }
    },
    // 生成编码
    handleGenerateCode () {
      // let validFlang = true
      let currn = 0
      let keys = Object.keys(this.formRule).filter(item => item !== 'pnCode')
      keys.forEach(key => {
        // debugger
        // console.log(key)
        this.$refs.formValidate.validateField(key, valid => {
          console.log(valid)
          if (!valid) currn = currn + 1
          if (currn === keys.length) {
            this.generatePn()
          }
        })
      })
      // if (validFlang) {

      // }
      // console.log(validFlang)
      // this.$refs.formValidate.validate( async valid => {
      //   console.log(valid)
      // })
    },
    // 生成PN编码
    generatePn () {
      const { C, Y1 } = this.PN
      const { nameAbbreviation, abbreName, machineVersion, yearCorp, salesAmount, slotQuantity } = this.formData

      this.formData.pnCode = `${C}${Y1}${nameAbbreviation}${
        Number(machineVersion) < 10 ? '0' + machineVersion : machineVersion
      }${abbreName}${dayjs(yearCorp).format('YY')}${salesAmount}${slotQuantity < 10 ? slotQuantity : 'X'}`
      this.copyData = cloneObj(this.formData)
    },
    // 选择一级分类
    handleMachineCategory (val) {
      // console.log(val)
      this.PN.C = val.label.slice(0, 1)
      this.formData.subMachineCategoryId = ''
      this.subMachineCategoryIdData = this.machineList.filter(item => item.parentId === val.value)
    },
    handleSubMachineCategory (val) {
      if (val) this.PN.Y1 = val.label.slice(0, 1)
      console.log(val)
    },
    // 提交表单
    handleSubmit () {
      this.$refs.formValidate.validate(valid => {
        if (valid) {
        //           name: '', // 名称
        // machineCategoryId: '', // 一级分类
        // subMachineCategoryId: '', // 二级分类
        // nameAbbreviation: '', // 名字缩写
        // machineSupplierId: '', // 供应商id
        // abbreName: '', // 供应商缩写
        // yearCorp: '', // 时间
        // salesAmount: '', // 销售数量
        // machineVersion: '', // 版本号
        // // seat: '', // 游戏位
        // slotQuantity: '', // 投币口数
          if (this.codeDisabled) return this.machineSave()
          let keys = ['name', 'machineCategoryId', 'subMachineCategoryId', 'nameAbbreviation', 'machineSupplierId', 'abbreName', 'yearCorp', 'salesAmount', 'machineVersion', 'slotQuantity']
          let change = false
          keys.map(key => {
            if (key === 'yearCorp') {
              if (!dayjs(this.formData[key]).isSame(dayjs(this.copyData[key]))) {
                change = true
              }
            } else {
              if (this.formData[key] !== this.copyData[key]) {
                change = true
              }
            }
          })
          if (!change) {
            this.machineSave()
          } else {
            this.$Modal.warning({
              title: '温馨提示',
              content: '数据发生变化，请点击生成编码按钮重新生成产品编码'
            })
            // console.log('数据变动')
          }
        }
      })
    },
    handleImg (index) {
      // console.log('设置为主图', index)
      // console.log(this.uploadList)
      let ele = this.uploadList.splice(index, 1)
      this.uploadList.unshift(...ele)
    },
    async machineSave () {
      if (!this.codeDisabled) {
        this.generatePn()
      }
      let uploadList = this.uploadList.map(item => item.url)
      if (this.uploadList.length) {
        if (this.imgIndex !== 0) {
          let arr = uploadList.slice(this.imgIndex, this.imgIndex + 1)
          uploadList.splice(this.imgIndex, 1)
          uploadList.unshift(...arr)
        }
      }
      uploadList.forEach((url, index) => {
        this.$set(this.formData, `pic${index + 1}`, url)
      })
      let formData = new FormData()
      Object.keys(this.formData).forEach(key => {
        if (key === 'lastModify' || key === 'dateCreated') return null
        formData.append(key, this.formData[key])
      })
      formData.append('merchantId', this.merchantId)

      const res = await machineSave(this.formData || formData)
      if (res.data.status !== 200) return this.$Message.error(res.data.error)
      this.$Message.success('提交成功')
      this.$router.go(-1)
    },
    async categoryList () {
      const [err, res] = await errorCaptured(categoryList, { merchantId: this.merchantId })
      if (err) return null
      if (this.$route.name === 'asset_manage_product_control_detail' || this.$route.name === 'asset_manage_product_control_edit') { this.machineQuery() }

      if (res) {
        if (res.data.status !== 200) return this.$Message.error(res.data.error)
        this.machineList = res.data.data || []
        this.machineCategoryIdData = (res.data.data || []).filter(item => !item.parentId)
      }
    },
    // 详情查询
    async machineQuery () {
      let formData = new FormData()
      formData.append('machineId', this.$route.params.id)
      const res = await machineQuery(formData)
      let obj = res.data.data || {}
      Object.keys(obj).forEach(key => {
        switch (key) {
          case 'machineVersion':
            this.$set(this.formData, key, Number(obj[key]))
            break
          case `pic1`:
          case `pic2`:
          case `pic3`:
          case `pic4`:
          case `pic5`:
            this.defaultList.push({ name: key, url: obj[key] })
            break
          case 'machineCategoryId':
            this.subMachineCategoryIdData = this.machineList.filter(item => item.parentId === obj[key])
            this.$set(this.formData, key, obj[key])
            break
          case 'pnCode':
            let nameAbbreviation = obj[key].slice(2, 4)
            this.$set(this.formData, 'nameAbbreviation', nameAbbreviation)
            this.$set(this.formData, key, obj[key])
            break
          case 'lastModify':
          case 'dateCreated':
            break
          default:
            this.$set(this.formData, key, obj[key])
            break
        }
      })
      this.$nextTick(() => {
        this.uploadList = this.$refs.upload.fileList
      })
      // this.formData = res.data.data || {}
    },
    // 点击去取消
    handleCancle () {
      this.$store.commit('closeTag', this.$route)
      this.$store.commit(
        'setTagNavList',
        this.$store.state.app.tagNavList.filter(item => !routeEqual(this.$route, item))
      )
    }
  }
}
</script>
<style lang="less" scoped>
.asset-manage-makerpn {
  margin: 0 auto;
  padding: 40px 80px;
  .asset-manage-makerpn-info {
    margin: 0 auto;
    min-width: 940px;
    max-width: 1000px;
  }
  .title {
    display: flex;
    align-items: center;
  }
  .title-icon {
    display: inline-block;
    height: 20px;
    width: 8px;
    background: #2d8cf0;
    margin-right: 10px;
  }

  .upload-list {
    display: inline-block;
    width: 96px;
    height: 96px;
    text-align: center;
    line-height: 96px;
    border: 1px solid transparent;
    border-radius: 4px;
    overflow: hidden;
    background: #fff;
    position: relative;
    box-shadow: 0 1px 1px rgba(0, 0, 0, 0.2);
    margin-right: 4px;
  }
  .upload-list img {
    width: 100%;
    height: 100%;
  }
  .upload-list-cover {
    display: none;
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(0, 0, 0, 0.6);
    color: #fff;
  }
  .upload-list-button {
    width: 76px;
    font-size: 12px;
    margin-top: 10px;
    align-self: center;
    margin-right: 2px;
  }
  .upload-list-p {
    height: 20px;
    position: absolute;
    top: 6px;
    /* right: 0; */
    background: #e7314e;
    line-height: 20px;
    left: 4px;
    padding: 0 4px;
  }
  .upload-list:hover .upload-list-cover {
    display: block;
  }
  .supload-list-cover i {
    color: #fff;
    font-size: 20px;
    cursor: pointer;
    margin: 0 2px;
  }

  .input-width {
    width: 260px;
  }

  .ivu-table-noborder td {
    border-bottom: none;
  }
  .ivu-table-noborder:before {
    content: '';
    width: 100%;
    height: 0px;
  }
  .ivu-table-noborder:after {
    content: '';
    width: 100%;
    height: 0px;
  }
  .ivu-table-border th,
  .ivu-table-border td {
    border-bottom: 1px solid #e8eaec;
  }
}
</style>
